# recognition/actions/swipe_left.py
from .swipe_base import SwipeBase
import math

class SwipeLeft(SwipeBase):
    label = "swipe_left"
    def direction_ok(self, dx, dy):
        # 左滑：x 负向，且 |dx| 主导
        ax, ay = abs(dx), abs(dy)
        # 方向对齐度：cos 与目标方向 (-1,0) 的相似度
        mag = math.hypot(dx, dy) + 1e-8
        cos = (-dx) / mag  # dx<0 时 cos 越接近 1
        # 主轴是否为 X
        main_is_x = ax >= ay
        ok = (dx < 0) and main_is_x
        align = max(0.0, min(1.0, cos))
        return ok, align